<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="msg">
        <h1>{{msg}}</h1>
        <my-com @subfun="cb"></my-com>
    </div>
    <template id="mytemp">
        <div>
            <my-com2></my-com2>
            <p>{{msg}}</p>
            <input type="button" value="触发向父组件传递数据" @click="send">
        </div>
    </template>
    <template id="mytemp2">
        <h4>{{msg}}</h4>
    </template>
</body>
<script>
    Vue.component("myCom",{
        template:"#mytemp",
            data(){
                return{
                    msg:"这是组件内部的变量"
                }
            },
            props:[],
            methods:{
                send(){
                    this.$emit('subfun',this.msg)
                }
            }
    })
    Vue.component("myCom2",{
        template:"#mytemp2",
        data(){
            return{
                msg:"这是第二个组件的数据"
            }
        }
    })
    var vm = new Vue({
        el:'#app',
        data:{
            msg:"123"
        },
        methods:{
            cb(arg){
                console.log(arg)
                this.msg=arg
            }
        }
    })
</script>
</html>